<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="mainId">
      <a-button @click="handleAdd" type="primary" icon="plus" v-show="!isChecked">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0 && !isChecked">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="materialCode" slot-scope="text, record">
          <div>
            <a-select
              :dropdownMatchSelectWidth="false"
              :showSearch="true"
              style="width: 100px"
              :value="selectValue"
              :maxTagCount="10"
              @search="searchMaterial"
              @blur="clearMaterialData"
              @focus="searchMaterial"
              @select="changeRecord($event, record)"
              @popupScroll="popupScroll"
              :filter-option="false"
              v-if="record.selectable"
            >
              <a-select-option v-for="(item, index) in materialData" :key="index">
                <span v-for="(i, index) in materialField" :key="index">
                  {{ item[i] }}
                  <a-divider type="vertical" style="background-color: #0c8fcf"></a-divider>
                </span>
              </a-select-option>
            </a-select>
            <template v-else slot-scope="text, record">
              {{ record.materialCode }}
            </template>
          </div>
        </template>
        <template slot="totalNumber" slot-scope="text, record">
          <a-input-number v-model:value="record.totalNumber" v-if="record.selectable"></a-input-number>
          <span v-else>{{ text }}</span>
        </template>
        <template slot="action" slot-scope="text, record">
          <div class="editable-row-operations" v-show="record.status !== 1">
            <span v-if="record.editable">
              <a @click="() => save(record)">保存</a>
              <a-divider type="vertical" style="background-color: grey"></a-divider>
              <a @click="() => cancel(record)">取消</a>
            </span>
            <span v-else>
              <a :disabled="editingKey !== ''" @click="edit(record)" v-show="!isChecked">编辑</a>
              <a-divider type="vertical" style="background-color: grey" v-show="!isChecked"></a-divider>
              <a :disabled="editingKey !== ''" @click="handleDelete(record.id)" v-show="!isChecked">删除</a>
            </span>
          </div>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { HfIODetailMixin } from '@/mixins/HfIODetailMixin'

export default {
  name: 'HfSaleoutDetailList',
  mixins: [JeecgListMixin, HfIODetailMixin],
  components: {},
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    },
    customId: {
      type: String,
      default: '',
      required: false
    },
    sourceSerial: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList()
        } else {
          this.queryParam['sourceId'] = val
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      description: '销售出库订单管理页面',
      disableMixinCreated: true,
      isChecked: false,
      // 表头
      columns: [
        {
          title: '序号',
          align: 'center',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          },
          width: 60
        },
        {
          title: '物料代码',
          align: 'center',
          dataIndex: 'materialCode',
          scopedSlots: { customRender: 'materialCode' }
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText'
        },
        {
          title: '物料类型',
          align: 'center',
          dataIndex: 'materialType_dictText'
        },
        {
          title: '物料单箱数',
          align: 'center',
          dataIndex: 'perNumber'
        },
        {
          title: '箱数',
          align: 'center',
          dataIndex: 'number'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'totalNumber',
          scopedSlots: { customRender: 'totalNumber' }
        },
        // {
        //   title: '单价',
        //   align: 'center',
        //   dataIndex: 'price'
        // },
        // {
        //   title: '税率',
        //   align: 'center',
        //   dataIndex: 'tax'
        // },
        // {
        //   title: '含税单价',
        //   align: 'center',
        //   dataIndex: 'taxPrice'
        // },
        // {
        //   title: '金额',
        //   align: 'center',
        //   dataIndex: 'totalPrice'
        // },
        {
          title: '发货仓库',
          align: 'center',
          dataIndex: 'warehouse_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/sale/hfSaleOut/listHfSaleOutDetailByMainId',
        delete: '/sale/hfSaleOut/deleteHfSaleOutDetail',
        deleteBatch: '/sale/hfSaleOut/deleteBatchHfSaleOutDetail',
        add: '/sale/hfSaleOut/addHfSaleOutDetail',
        edit: '/sale/hfSaleOut/editHfSaleOutDetail'
      },
      dictOptions: {
        saleType: []
      }
    }
  },
  created() {},
  computed: {
    importExcelUrl() {
      return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`
    }
  },
  methods: {
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
